<?php

require_once dirname(__FILE__) . '/TestCase.php';
require_once 'Auth/Vidoop/Secure/EnrollmentService.php';

class Auth_Vidoop_Secure_EnrollmentParseTest extends Auth_Vidoop_Secure_TestCase {

	public function testImageResponseParsing() {
		$xml = file_get_contents($this->data_dir . 'image_response_1.xml');
		$images = Auth_Vidoop_Category_Image::from_images_xml($xml);

		$this->assertEquals(1, sizeof($images));
		$this->assertEquals('https://api.vidoop.com/vs/images/aLongRandomString/image', $images[0]->uri);
	}

	public function testCategoryResponseParsing() {
		$xml = file_get_contents($this->data_dir . 'category_response_1.xml');
		$category = Auth_Vidoop_Category::from_xml($xml);

		$this->assertEquals('catid1', $category->id);
		$this->assertEquals('category 1 name', $category->name);
		$this->assertEquals(1, sizeof($category->images));
		$this->assertEquals('https://api.vidoop.com/vs/categories/catid1/representative_images/img123', $category->images[0]->uri);
	}

	public function testCategoriesResponseParsing() {
		$xml = file_get_contents($this->data_dir . 'categories_response_1.xml');
		$categories = Auth_Vidoop_Category::from_categories_xml($xml);

		$this->assertEquals(2, sizeof($categories));

		$this->assertEquals('catid1', $categories[0]->id);
		$this->assertEquals('category 1 name', $categories[0]->name);
		$this->assertEquals(1, sizeof($categories[0]->images));
		$this->assertEquals('https://api.vidoop.com/vs/categories/catid1/representative_images/img123', $categories[0]->images[0]->uri);

		$this->assertEquals('catid2', $categories[1]->id);
		$this->assertEquals('category 2 name', $categories[1]->name);
		$this->assertEquals(2, sizeof($categories[1]->images));
		$this->assertEquals('https://api.vidoop.com/vs/categories/catid2/representative_images/img123', $categories[1]->images[0]->uri);
		$this->assertEquals('https://api.vidoop.com/vs/categories/catid2/representative_images/img456', $categories[1]->images[1]->uri);
	}

}
